package 每日一题;

public class 半径为k的子数组平均值 {
    //前缀和问题
    public int[] getAverages(int[] nums, int k) {
        int n = nums.length;
        long[] preSum = new long[n + 1];
        for (int i = 0; i < n; i++) {
            preSum[i+1] = preSum[i] + nums[i];
        }
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            if (i<k || i+k>=n){
                res[i] = -1;
            }
            else{
               res[i] =(int)((preSum[i+k+1]-preSum[i-k])/(2*k+1));
            }
        }
        return res;
    }
}
